#include "options.h"
#ifdef __linux__
#include<unistd.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "../../api/api.h"

void processVadOption(vadOptions* pOptions)
{
	if (!pOptions->_iSampleRatioGiven)
		pOptions->_iSampleRatio = 8000;
	if (!pOptions->_iVadFilePathGiven)
	{
		const char* filePath = getenv ("RECO_VAD_FILEPATH");
		if(filePath)
		{
			pOptions->_iVadFilePathGiven =1;
			int iLen = strlen(filePath);
			strncpy(pOptions->_vadFilePath,filePath,iLen);
			pOptions->_iVadFilePathLen = iLen;
		}
		else
		{
			strncpy(pOptions->_vadFilePath,"/tmp/",5);
			pOptions->_iVadFilePathLen = 5;
		}
	}
	if (!pOptions->_iVadRenderGiven)
		pOptions->_iVadRenderId = RECO_WEBRTC;
#ifdef __linux__
	if (access(pOptions->_vadFilePath,F_OK) != 0)
	{
		char cmd[512];
		sprintf(cmd,"mkdir %s -p",pOptions->_vadFilePath);
		system(cmd);
	}
#endif
}
void processGobalEnv()
{
	bool bExit = false;
	char* pEnv = getenv("RECO_VAD_APPID");
	if(!pEnv)
	{
		bExit = true;
		printf("Env RECO_VAD_APPID must be set!\n");
	}
	pEnv = getenv("RECO_VAD_APIKEY");
	if(!pEnv)
        {
		bExit = true;
                printf("Env RECO_VAD_APIKEY must be set!\n");
        }
	pEnv = getenv("RECO_VAD_APISECRET");
	if(!pEnv)
	{
		bExit = true;
                printf("Env RECO_VAD_APISECRET must be set!\n");
        }
	if(bExit)
		exit(1);
}

